package com.xgzit.xgzmall.search.config;

import brave.sampler.Sampler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.sleuth.sampler.ProbabilityBasedSampler;
import org.springframework.cloud.sleuth.sampler.SamplerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 解决 引入zipkin 项目启动不了 。原因是：加入zipkin依赖会和redis相关产生死锁
 * 具体参考： https://www.jianshu.com/p/1442b7cb4f5f
 * @Author xgz
 * @Date 2021-07-18 16:03
 */
@Configuration
public class SleuthSamplerConfiguration {
    @Value("${spring.sleuth.sampler.probability}")
    private String probability;

    @Bean
    public Sampler defaultSampler() throws Exception {
        Float f = new Float(probability);
        SamplerProperties samplerProperties = new SamplerProperties();
        samplerProperties.setProbability(f);
        return new ProbabilityBasedSampler(samplerProperties);
    }
}
